/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SaveAsDialog.java
 *
 * Created on 04.02.2011, 13:57:56
 */

package mybox.jcadgui;

import java.awt.Color;
import javax.swing.filechooser.FileFilter;

/**
 *
 * @author hassler
 */
@SuppressWarnings("serial")
public class SaveAsDialog extends javax.swing.JDialog {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	String directoryStr;
    String chosenFileStr;

    /** Creates new form SaveAsDialog */
    public SaveAsDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        FileFilter dxfType = new ExtensionFilter(".dxf", ".dxf");        
        this.jFileChooser1.setFileFilter(dxfType);
        this.jFileChooser1.showSaveDialog(this); 
        
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.

     */   
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents

    private void initComponents() {

        jFileChooser1 = new javax.swing.JFileChooser();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jFileChooser1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jFileChooser1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jFileChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jFileChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 445, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(104, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents


    private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFileChooser1ActionPerformed
        // TODO add your handling code here:
        System.out.println("ActionPerformed"+evt.getActionCommand());
        if (evt.getActionCommand().equalsIgnoreCase("ApproveSelection")) {
            System.out.println("File chosen");
            directoryStr=this.jFileChooser1.getCurrentDirectory().toString();
            chosenFileStr=this.jFileChooser1.getSelectedFile().getName();
            if (!chosenFileStr.endsWith(".dxf")) chosenFileStr=chosenFileStr+".dxf";
            dispose();
        }
        if (evt.getActionCommand().equalsIgnoreCase("CancelSelection")) {
            dispose();
        }
        
    }//GEN-LAST:event_jFileChooser1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                SaveAsDialog dialog = new SaveAsDialog(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFileChooser jFileChooser1;
    // End of variables declaration//GEN-END:variables

}

